package com.bkbw.live.battle.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 文件读写的工具类
 * @author zhouyou
 *
 */
public class FileUtils {
	/**
	 * 比如读取map文件夹中的map1.json，则参数传"map/map1.json"
	 * @param path
	 * @return
	 */
	public static String getStringFromFile(String path){
		StringBuilder sb = new StringBuilder();
		try {
			//把文件内容读取为字符串
			BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(path))));
			String line = null;
			while((line=reader.readLine())!=null){
				sb.append(line);
			}
			//关闭流
			reader.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return sb.toString();
	}
	
	
}
